package com.pengshun.modules.api.pay.service;

import java.util.Map.Entry;
import java.util.SortedMap;

/**
 * @author luoligang
 */
public class XmlUtil {

    private static final String PREFIX_XML = "<xml>";

    private static final String SUFFIX_XML = "</xml>";

    /**
     * 转化成xml
     * @param parm
     * @return
     */
    public static String xmlFormat(SortedMap<String, String> parm) {
        StringBuffer strbuff = new StringBuffer(PREFIX_XML);
        if (parm==null || parm.isEmpty()) {
            return strbuff.append(SUFFIX_XML).toString();
        }
        for (Entry<String, String> entry : parm.entrySet()) {
            strbuff.append("<").append(entry.getKey()).append(">");
            strbuff.append("<![CDATA["+entry.getValue()+"]]>");
            strbuff.append("</").append(entry.getKey()).append(">");
        }
        return strbuff.append(SUFFIX_XML).toString();
    }

}
